package com.example.administrator.listviewdemo;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/12/2 0002.
 */

public class KyanaAdapter extends ArrayAdapter<Kyana> {
    private int resouceId;
    public KyanaAdapter(Context context, int resource, List<Kyana> objects) {
        super(context, resource, objects);
        resouceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Kyana kyana = getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null) {
            view = LayoutInflater.from(getContext()).inflate(resouceId, null);
            viewHolder = new ViewHolder();
            viewHolder.kyanaName = (TextView)view.findViewById(R.id.kyana_name);
            viewHolder.kyanaID =(TextView)view.findViewById(R.id.kyana_id);
            view.setTag(viewHolder);
        }
        else{
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }
        viewHolder.kyanaName.setText(kyana.getName());
        viewHolder.kyanaID.setText(Integer.toString(kyana.getId()));
        return view;
    }
    class ViewHolder{
        TextView kyanaName;
        TextView kyanaID;
    }
}
